package com.iwomy.secureplat.admin.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.secureplat.admin.api.entity.SysMonitorTypeEntity;
import com.iwomy.secureplat.admin.service.SysMonitorTypeService;
import com.iwomy.secureplat.common.core.util.R;
import com.iwomy.secureplat.common.log.annotation.SysLog;

import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.secureplat.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消防监管类别，单位类别
 *
 * @author pig
 * @date 2023-11-08 14:04:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysMonitorType" )
@Tag(description = "sysMonitorType" , name = "消防监管类别，单位类别管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SysMonitorTypeController {

    private final SysMonitorTypeService sysMonitorTypeService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysMonitorType 消防监管类别，单位类别
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_sysMonitorType_view')" )
    public R getSysMonitorTypePage(@ParameterObject Page page, @ParameterObject SysMonitorTypeEntity sysMonitorType) {
        LambdaQueryWrapper<SysMonitorTypeEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(sysMonitorTypeService.page(page, wrapper));
    }


    /**
     * 通过id查询消防监管类别，单位类别
     * @param monitorId id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{monitorId}" )
//    @PreAuthorize("@pms.hasPermission('platform_sysMonitorType_view')" )
    public R getById(@PathVariable("monitorId" ) Long monitorId) {
        return R.ok(sysMonitorTypeService.getById(monitorId));
    }

    /**
     * 新增消防监管类别，单位类别
     * @param sysMonitorType 消防监管类别，单位类别
     * @return R
     */
    @Operation(summary = "新增消防监管类别，单位类别" , description = "新增消防监管类别，单位类别" )
    @SysLog("新增消防监管类别，单位类别" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_sysMonitorType_add')" )
    public R save(@RequestBody SysMonitorTypeEntity sysMonitorType) {
        return R.ok(sysMonitorTypeService.save(sysMonitorType));
    }

    /**
     * 修改消防监管类别，单位类别
     * @param sysMonitorType 消防监管类别，单位类别
     * @return R
     */
    @Operation(summary = "修改消防监管类别，单位类别" , description = "修改消防监管类别，单位类别" )
    @SysLog("修改消防监管类别，单位类别" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_sysMonitorType_edit')" )
    public R updateById(@RequestBody SysMonitorTypeEntity sysMonitorType) {
        return R.ok(sysMonitorTypeService.updateById(sysMonitorType));
    }

    /**
     * 通过id删除消防监管类别，单位类别
     * @param ids monitorId列表
     * @return R
     */
    @Operation(summary = "通过id删除消防监管类别，单位类别" , description = "通过id删除消防监管类别，单位类别" )
    @SysLog("通过id删除消防监管类别，单位类别" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_sysMonitorType_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(sysMonitorTypeService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param sysMonitorType 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_sysMonitorType_export')" )
    public List<SysMonitorTypeEntity> export(SysMonitorTypeEntity sysMonitorType,Long[] ids) {
        return sysMonitorTypeService.list(Wrappers.lambdaQuery(sysMonitorType).in(ArrayUtil.isNotEmpty(ids), SysMonitorTypeEntity::getMonitorId, ids));
    }

	/**
	 * 获取消防监管类别，单位类别列表
	 * @return  消防监管类别，单位类别列表
	 */
	@GetMapping("/list")
	public R listMonitorType() {
		return R.ok(sysMonitorTypeService.list(Wrappers.emptyWrapper()));
	}

}